package com.xhblog.handler;

import com.xhblog.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @ControllerAdvice：对加了@Controller注解的类进行拦截处理aop的实现
 */

/**
 * @author pengyouhong
 * create 2022/5/18 14:42
 */
@Log4j2
@ControllerAdvice
@ResponseBody
public class AllExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result doException(Exception exception) {

        exception.printStackTrace();

        //打印错误日志
        log.error(exception.getMessage());
        return Result.fail(-999, "系统异常");
    }
}
